package form.ui
{
	import flash.events.MouseEvent;
	import flash.text.TextFieldAutoSize;
	
	import form.interfaces.IFormElement;

	public class LinkButton extends Label implements IFormElement
	{
		public function LinkButton()
		{
			super();
			
			this.textfield.mouseEnabled = false;
			this.autoSize = TextFieldAutoSize.LEFT;
			
			this.addEventListener(MouseEvent.ROLL_OVER, onRollOver, false, 0, true);
			this.addEventListener(MouseEvent.ROLL_OUT, onRollOut,false, 0, true);
			this.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown, false, 0, true);
			this.addEventListener(MouseEvent.MOUSE_UP, onRollOut, false, 0, true);
			
			this.enable();
		}
		
		private function onRollOver(e:MouseEvent):void
		{
			this.fontColor = this.hoverColor;
		}
		
		private function onRollOut(e:MouseEvent = null):void
		{
			this.fontColor = this.upColor;
		}
		
		private function onMouseDown(e:MouseEvent):void
		{
			this.fontColor = this.downColor;
		}
		
		
		override public function enable():void
		{
			super.enable();
			this.buttonMode = true;
			this.mouseEnabled = true;
			this.mouseChildren = true;
			onRollOut();
		}
		
		override public function disable():void
		{
			super.disable();
			this.buttonMode = false;
			this.mouseEnabled = false;
			this.mouseChildren = false;
		}
		
		private var _upColor:uint = 0xFFFFFF;
		public function set upColor(value:uint):void
		{
			if(_upColor != value)
			{
				_upColor = value;
				draw();
			}
			
		}
		public function get upColor():uint
		{
			return _upColor;
		}
		
		private var _hoverColor:uint = 0xFFFFFF;
		public function set hoverColor(value:uint):void
		{
			if(_hoverColor != value)
			{
				_hoverColor = value;
				draw();
			}
			
		}
		public function get hoverColor():uint
		{
			return _hoverColor;
		}
		
		private var _downColor:uint = 0xCCCCCC;
		public function set downColor(value:uint):void
		{
			if(_downColor != value)
			{
				_downColor = value;
				draw();
			}
		}
		public function get downColor():uint
		{
			return _downColor;
		}
		
		private var _disableColor:uint = 0xCCCCCC;
		public function set disableColor(value:uint):void
		{
			if(_disableColor != value)
			{
				_disableColor = value;
				draw();
			}
		}
		public function get disableColor():uint
		{
			return _disableColor;
		}
		
		/* override public function set formValue(value:String):void
		{
			super.formValue = value;
		} */
		
		override public function draw():void
		{
			super.draw();
			if(textfield)onRollOut();			
		}
		
	}
}